<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>inde</title>
</head>

<body>

<form action="" method="post" class="login"> 
    <div><label>Username</label><input name="user" type="text" ></div> 
    <div><label>Password</label><input name="password" type="password"></div> 
    <div><input name="login" type="submit" value="login"></div> 
</form> 
</body>
</html>

<?php
$server = "localhost";
$usu = "Magsi";
$paw = "Magsi"; //depende de tu pass de mysql 

$conexion = mysql_connect($server, $usu, $paw);
$db = mysql_select_db("magsi_db", $conexion);


session_start(); 
  
function verificar_login($user,$password,&$result) { 
    $sql = "SELECT * FROM ma_sa_usuario WHERE MA_V_UsuASA = '$user' and MA_V_Contras = '$password'"; 
    $rec = mysql_query($sql); 
    $count = 0; 
  
    while($row = mysql_fetch_object($rec)) 
    { 
        $count++; 
        $result = $row; 
    } 
  
    if($count == 1) 
    { 
        return 1; 
    } 
  
    else 
    { 
        return 0; 
    } 
} 
  
if(!isset($_SESSION['userid'])) 
{ 
    if(isset($_POST['login'])) 
    { 
        if(verificar_login($_POST['user'],$_POST['password'],$result) == 1) 
        { 
            $_SESSION['userid'] = $result->idusuario; 
            header("location:index2.php"); 
        } 
        else 
        { 
            echo '<div class="error">Su usuario es incorrecto, intente nuevamente.</div>'; 
        } 
    } 
	?> 
    
    
    
	<?php 
} else { 
    echo 'Su usuario se ingreso correctamente.'; 
    echo '<a href="logOutBD.php">Logout</a>'; 
} 
?>

